var e = require;
var t = module;
var o = exports;
var n;
Object.defineProperty(o, "__esModule", {value: !0});
var r = e("SDK"),
    s = e("AdUtils"),
    c = cc._decorator,
    l = c.ccclass,
    d =
        (c.property,
        (function (e) {
            function t() {
                var t = (null !== e && e.apply(this, arguments)) || this;
                return (t._videoAd = null), (t._caretorIntervalType = !0), t;
            }
            return (
                __extends(t, e),
                (t.prototype.init = function (e) {
                    (this._config = e), (this._isVideo = !0), s.default.instance.log("创建Video广告");
                    var t = this;
                    this.scheduleOnce(function () {
                        t.initRewardVideo();
                    }, 2);
                }),
                (t.prototype.initRewardVideo = function () {
                    var e = this;
                    if (this._caretorIntervalType) {
                        var t = this;
                        if (this._config) {
                            var o = this._config.video_ad_code;
                            s.default.instance.log("-------激励视频创建----- " + o),
                                this._caretorIntervalType &&
                                    ((this._caretorIntervalType = !1),
                                    (this._videoAd = qg.createRewardedVideoAd({posId: o}))),
                                this.scheduleOnce(function () {
                                    e._caretorIntervalType = !0;
                                }, 2),
                                this._videoAd.onError(function (e) {
                                    s.default.instance.log("激励视频广告加载失败" + JSON.stringify(e)),
                                        (t._loadVideo = !1);
                                }),
                                this._videoAd.onLoad(function () {
                                    s.default.instance.log("激励视频加载成功"), (t._loadVideo = !0);
                                }),
                                this._videoAd.onClose(function (e) {
                                    (t._loadVideo = !1),
                                        e && e.isEnded
                                            ? (s.default.instance.log("激励视频广告完成，发放奖励"),
                                              r.default.Instance.reportLog(
                                                  r.NodeAction.VIDEO_CLOSE,
                                                  "激励视频广告完成，发放奖励"
                                              ),
                                              t._callBacks && t._callBacks())
                                            : (s.default.instance.log("激励视频广告取消关闭，不发放奖励"),
                                              r.default.Instance.reportLog(
                                                  r.NodeAction.VIDEO_CLOSE,
                                                  "激励视频广告取消关闭，不发放奖励"
                                              ),
                                              t._fail && t._fail()),
                                        (t._callBacks = null),
                                        (t._fail = null),
                                        t.loadRewardVideo();
                                });
                        } else this._noAd && this._noAd();
                    }
                }),
                (t.prototype.loadRewardVideo = function () {
                    console.log("loadReardVideo: ", this._videoAd),
                        this._videoAd ? this._videoAd.load() : this.initRewardVideo();
                }),
                (t.prototype.showRewardVideo = function (e, t, o) {
                    var n = this;
                    (this._callBacks = e),
                        (this._fail = t),
                        (this._noAd = o),
                        this._isVideo && this._videoAd && this._loadVideo
                            ? this._videoAd
                                  .show()
                                  .then(function () {
                                      r.default.Instance.reportLog(r.NodeAction.VIDEO_SHOW, "激励视频广告展示"),
                                          s.default.instance.log("激励视频广告展示成功");
                                  })
                                  .catch(function (e) {
                                      n._noAd && n._noAd(),
                                          n.loadRewardVideo(),
                                          s.default.instance.log("激励视频广告展示失败： " + JSON.stringify(e));
                                  })
                            : (this._noAd && this._noAd(), this.loadRewardVideo());
                }),
                __decorate([l], t)
            );
        })(cc.Component));
o.default = d;
